home *** CD-ROM | disk | FTP | other *** search
- ;-------------------------hex16in routine begins--------------------------+
- ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
- ; page : 51
- ;
- ; NAME HEX16IN
- ; ROUTINE FOR Conversion from ASCII Hexidecimal to 16-bit binary
- ;
- ; FUNCTION: This routine accepts a hexidecimal number from the std input
- ; device and converts it to internal 16-bit binary form.
- ;
- ; INPUT: The individual digits of the hexxidecimal number are received in
- ; ASCII through a call to a std I/O routine. The valid digits are 0 - 9
- ; and A - F. An ASCII code for other than a valid digit will terminate
- ; the routine.
- ; OUTPUT: A 16-bit binary number is returned in DX.
- ; REGISTERS USED: Only DX is modified. It returns the result.
- ; SEGMENTS REFERENCED: None
- ; ROUTINES CALLED: STDIN
- ; SPECIAL NOTES: None
- ;
- ; ROUTINE TO CONVERT FROM ASCII HEXIDECIMAL TO INTERNAL 16-BIT BINARY.
- ;
- hex16in proc far
- ;
- push cx ; save registers
- push ax
- ;
- mov dx,0 ; initialize DX
- ;
- hex16in1:
- call stdin ; a digit comes in in AL
- sub al,30h ; reduce from ASCII
- jl hex16in3 ; check if too low
- cmp al,9
- jle hex16in2 ; go of OK
- and al,5Fh ; for lower case too
- sub al,7 ; adjust for A - F
- jl hex16in3 ; too low for A - F
- cmp al,15 ; check if too high
- jg hex16in3
- ;
- hex16in2:
- cbw ; convert to word
- mov cl,4 ; for a count of four
- sal dx,cl ; shift DX left
- add dx,ax ; add in digit
- jmp hex16in1
- ;
- hex16in3:
- pop ax ; restore registers
- pop cx
- ret ; return
- ;
- hex16in endp
- ;-------------------------hex16in routine ends---------------------------+